using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.ImageFilter;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Resources;
using System.Windows.Threading;
namespace MicroMsg.UI.UserContrl
{
	public class SmileyOverlay : UserControl
	{
		public const int SmileyEnter = -1;
		public const int SmileyBackSpace = -2;
		private const int SmileyCount = 105;
		private const string TAG = "SmileyOverlay";
		private const int QQSmileyViewIndex = 0;
		private const int EmojiSmileyViewIndex = 1;
		private const int ArtSmileyViewIndex = 2;
		private const int CustomSmileyViewIndex = 3;
		private const double cDMoveRestrict = 25.0;
		private const int CUSTOM_SMILEY_WIDTH = 111;
		private static WriteableBitmap[] SmileyBmpArray;
		private static bool isLoad = false;
		private bool isLoadSmiley;
		private bool isInitSmiley;
		private SimileyPad[] AllGrid;
		public SmileyClick Click;
		private List<string> smileyStack = new List<string>();
		private bool isInitArtSmileyBtn;
		private SimileyPad[] AllEmojiGrid;
		public SmileyClick EmojiClick;
		private GridPanel[] AllCustomGrid;
		private List<CustomSmiley> allCustomSmiley;
		private bool isDeleteState;
		public MMInputer mmInputer;
		private int pageIndexSelectPic;
		private double lastCliclTime;
		private bool isPreviewMode;
		private bool isUserSlide;
		private DispatcherTimer checkSlideTimer;
		private CustomSmiley lastTouchItem;
		private int lastTouchItemIndex;
		private double startX;
		private double startY;
		private bool isCustomSmileyClickable = true;
		public static DependencyProperty bIsWithoutArtSmileyProperty = DependencyProperty.Register("bIsWithoutArtSmiley", typeof(bool), typeof(SmileyOverlay), new PropertyMetadata(false, new PropertyChangedCallback(SmileyOverlay.bIsWithoutArtSmileyPropertyChanged)));
		internal Canvas RootLayout;
		internal ViewFlipper SmileyFliper;
		internal Grid QQSmileyView;
		internal Pivot mSmileyPivot;
		internal SimileyPad SmileyGrid1;
		internal SimileyPad SmileyGrid2;
		internal SimileyPad SmileyGrid3;
		internal SmileyViewDot SmileySelect;
		internal Grid EmojiSmileyView;
		internal Pivot mEmojiPivot;
		internal SimileyPad EmojiGrid1;
		internal SimileyPad EmojiGrid2;
		internal SimileyPad EmojiGrid3;
		internal SimileyPad EmojiGrid4;
		internal SimileyPad EmojiGrid5;
		internal SmileyViewDot EmojiSelect;
		internal Grid ArtSmileyView;
		internal GridPanel ArtSmileyGrid1;
		internal Grid CustomSmileyView;
		internal Pivot mCustomPivot;
		internal SmileyViewDot CustomSelect;
		internal ImageButton QQSmileyButton;
		internal ImageButton EmojiSmileyButton;
		internal ImageButton ArtSmileyButton;
		internal ImageButton CustomSmileyButton;
		internal Grid preViewLayout;
		private bool _contentLoaded;
		public bool bIsWithoutArtSmiley
		{
			get
			{
				return (bool)base.GetValue(SmileyOverlay.bIsWithoutArtSmileyProperty);
			}
			set
			{
				base.SetValue(SmileyOverlay.bIsWithoutArtSmileyProperty, value);
			}
		}
		private WriteableBitmap CutImage(WriteableBitmap writeableBitmap_0, double double_0, double double_1, double width, double height)
		{
			if (width >= 0.0 && height >= 0.0)
			{
				Image image = new Image();
				image.set_Stretch(0);
				UIElement arg_51_0 = image;
				TranslateTransform translateTransform = new TranslateTransform();
				translateTransform.set_X(-1.0 * double_0);
				translateTransform.set_Y(-1.0 * double_1);
				arg_51_0.set_RenderTransform(translateTransform);
				image.set_Source(writeableBitmap_0);
				Canvas canvas = new Canvas();
				canvas.set_Width(width);
				canvas.set_Height(height);
				canvas.get_Children().Add(image);
				return new WriteableBitmap(canvas, null);
			}
			return null;
		}
		private static WriteableBitmap LoadBmp(string imgSrc)
		{
			if (string.IsNullOrEmpty(imgSrc))
			{
				return null;
			}
			Uri uri = new Uri(imgSrc, 2);
			StreamResourceInfo resourceStream = Application.GetResourceStream(uri);
			if (resourceStream == null)
			{
				return null;
			}
			BitmapImage bitmapImage = new BitmapImage();
			bitmapImage.SetSource(resourceStream.get_Stream());
			Image image = new Image();
			image.set_Source(bitmapImage);
			image.set_Stretch(0);
			if (bitmapImage.get_PixelWidth() != 0 && bitmapImage.get_PixelHeight() != 0)
			{
				image.set_Width((double)bitmapImage.get_PixelWidth());
				image.set_Height((double)bitmapImage.get_PixelHeight());
				int arg_74_0 = bitmapImage.get_PixelWidth();
				int arg_7B_0 = bitmapImage.get_PixelHeight();
				WriteableBitmap writeableBitmap = new WriteableBitmap((int)image.get_Width(), (int)image.get_Height());
				writeableBitmap.Render(image, null);
				writeableBitmap.Invalidate();
				return writeableBitmap;
			}
			return null;
		}
		public static void PreLoad()
		{
			if (SmileyOverlay.isLoad)
			{
				return;
			}
			int smileyCount = SmileyManager.GetInstance().getSmileyCount();
			SmileyOverlay.SmileyBmpArray = new WriteableBitmap[smileyCount];
			for (int i = 0; i < smileyCount; i++)
			{
				SmileyOverlay.SmileyBmpArray[i] = SmileyOverlay.LoadBmp(SmileyManager.GetInstance().getLoadSmileySrc(i));
			}
			SmileyOverlay.isLoad = true;
		}
		public SmileyOverlay()
		{
			base.add_Loaded(new RoutedEventHandler(this.SmileyOverlay_Loaded));
			this.InitializeComponent();
			this.AllGrid = new SimileyPad[]
			{
				this.SmileyGrid1,
				this.SmileyGrid2,
				this.SmileyGrid3
			};
			this.AllEmojiGrid = new SimileyPad[]
			{
				this.EmojiGrid1,
				this.EmojiGrid2,
				this.EmojiGrid3,
				this.EmojiGrid4,
				this.EmojiGrid5
			};
			this.initCustomSmiley();
			this.setHighLight(this.QQSmileyButton);
			this.LoadSmiley(0);
		}
		private void SmileyOverlay_Loaded(object sender, RoutedEventArgs e)
		{
			if (!this.isLoadSmiley)
			{
				this.isLoadSmiley = true;
				this.QQSmileyButton.showAsPressed();
				base.get_Dispatcher().BeginInvoke(delegate
				{
				});
			}
		}
		private void SmileyOverlay_mItemClicked(object sender, object args)
		{
			this.silImage_ClickProc((int)args);
		}
		private void silImage_ClickProc(int nIndex)
		{
			if (this.Click != null)
			{
				this.Click(nIndex);
			}
		}
		private void smilImage_Click(object sender, RoutedEventArgs e)
		{
			ImageButton imageButton = sender as ImageButton;
			if (imageButton == null)
			{
				return;
			}
			int nIndex;
			if (imageButton.get_Tag() is string)
			{
				nIndex = int.Parse(imageButton.get_Tag() as string);
			}
			else
			{
				nIndex = (int)imageButton.get_Tag();
			}
			this.silImage_ClickProc(nIndex);
		}
		private void mSmileyPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			this.SmileySelect.SelectIndex = this.mSmileyPivot.SelectedIndex;
		}
		public void PushSmileyStack(string smileyStr)
		{
			if (string.IsNullOrEmpty(smileyStr))
			{
				return;
			}
			this.smileyStack.Add(smileyStr);
		}
		public void ClearSmileyStack()
		{
			this.smileyStack.Clear();
		}
		public string RemoveLastSmiley(string allTxt)
		{
			if (string.IsNullOrEmpty(allTxt))
			{
				return "";
			}
			bool flag = false;
			for (int i = this.smileyStack.get_Count() - 1; i >= 0; i--)
			{
				if (allTxt.EndsWith(this.smileyStack.get_Item(i)))
				{
					allTxt = allTxt.Substring(0, allTxt.get_Length() - this.smileyStack.get_Item(i).get_Length());
					this.smileyStack.RemoveAt(i);
					flag = true;
					IL_6D:
					if (!flag && allTxt.get_Length() >= 1)
					{
						allTxt = allTxt.Substring(0, allTxt.get_Length() - 1);
					}
					return allTxt;
				}
			}
			goto IL_6D;
		}
		private void QQSmileyButton_Click(object sender, RoutedEventArgs e)
		{
			this.SmileyFliper.ShowView(0);
			this.setHighLight(sender);
		}
		private void EmojiSmileyButton_Click(object sender, RoutedEventArgs e)
		{
			this.SmileyFliper.ShowView(1);
			this.setHighLight(sender);
		}
		private void ArtSmileyButton_Click(object sender, RoutedEventArgs e)
		{
			this.InitArtSmileyBtn();
			this.SmileyFliper.ShowView(2);
			this.setHighLight(sender);
		}
		private void CustomSmileyButton_Click(object sender, RoutedEventArgs e)
		{
			this.SmileyFliper.ShowView(3);
			this.setHighLight(sender);
		}
		private void setHighLight(object clickedButton)
		{
			if (this.QQSmileyButton == clickedButton)
			{
				this.QQSmileyButton.showAsPressed();
			}
			else
			{
				this.QQSmileyButton.showAsNotPressed();
			}
			if (this.EmojiSmileyButton == clickedButton)
			{
				this.EmojiSmileyButton.showAsPressed();
			}
			else
			{
				this.EmojiSmileyButton.showAsNotPressed();
			}
			if (this.ArtSmileyButton == clickedButton)
			{
				this.ArtSmileyButton.showAsPressed();
			}
			else
			{
				this.ArtSmileyButton.showAsNotPressed();
			}
			if (this.CustomSmileyButton == clickedButton)
			{
				this.CustomSmileyButton.showAsPressed();
				return;
			}
			this.CustomSmileyButton.showAsNotPressed();
		}
		private void ArtSmileyBtn_Click(object sender, RoutedEventArgs e)
		{
			Button button = sender as Button;
			if (button == null)
			{
				return;
			}
			if (button.get_Tag() == null)
			{
				return;
			}
			EmojiArtGroup group = button.get_Tag() as EmojiArtGroup;
			if (!EmojiListCtrl.IsNeedResponse())
			{
				return;
			}
			ChatPageCtrl cuChatPage = ChatContainerPage.getCuChatPage();
			BasePage topPage = PageManager.getInstance().GetTopPage();
			SendMessagePage sendMessagePage = null;
			if (topPage is SendMessagePage)
			{
				sendMessagePage = (topPage as SendMessagePage);
			}
			if (sendMessagePage == null)
			{
				if (cuChatPage != null)
				{
					cuChatPage.CheckEmojiListCtrl();
					if (cuChatPage.mEmojiListCtrl == null)
					{
						return;
					}
					cuChatPage.SwitchMode(ChatInputMode.InputDefault, false);
					cuChatPage.mEmojiListCtrl.SelectCustomEmoji(cuChatPage, new EmojiSelectComplete(cuChatPage.EmojiSelectComplete), group);
				}
				return;
			}
			sendMessagePage.CheckEmojiListCtrl();
			if (sendMessagePage.mEmojiListCtrl == null)
			{
				return;
			}
			sendMessagePage.SwitchMode(ChatInputMode.InputDefault, false);
			sendMessagePage.mEmojiListCtrl.SelectCustomEmoji(sendMessagePage, new EmojiSelectComplete(sendMessagePage.EmojiSelectComplete), group);
		}
		public void InitArtSmileyBtn()
		{
			if (this.isInitArtSmileyBtn)
			{
				return;
			}
			this.isInitArtSmileyBtn = true;
			List<EmojiArtGroup> list = StorageMgr.emojiArtGroup.getList();
			if (list != null && list.get_Count() > 0)
			{
				using (List<EmojiArtGroup>.Enumerator enumerator = list.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						EmojiArtGroup current = enumerator.get_Current();
						if (current != null)
						{
							ArtEmojiButton artEmojiButton = new ArtEmojiButton();
							artEmojiButton.Text = this.GetArtGroupNameByLan(current);
							artEmojiButton.ArtImgSource = this.getArtGroupImgSrc(current);
							artEmojiButton.set_Tag(current);
							artEmojiButton.add_Click(new RoutedEventHandler(this.ArtSmileyBtn_Click));
							this.ArtSmileyGrid1.get_Children().Add(artEmojiButton);
						}
					}
				}
				return;
			}
		}
		private ImageSource getArtGroupImgSrc(EmojiArtGroup group)
		{
			if (group == null)
			{
				return null;
			}
			if (string.IsNullOrEmpty(group.strIcon))
			{
				return null;
			}
			int emojiPos = EmojiManager.GetInstance().getEmojiPos(group.strIcon.get_Chars(0));
			if (emojiPos < 0)
			{
				return null;
			}
			return new ImageSourceConverter().ConvertFromString(EmojiManager.GetInstance().getEmojiSrcFromFilePos(emojiPos)) as ImageSource;
		}
		private string GetArtGroupNameByLan(EmojiArtGroup group)
		{
			if (group == null)
			{
				return "";
			}
			if (R.isChineseCN())
			{
				return group.strPackName_zh_cn;
			}
			if (R.isChineseTW())
			{
				return group.strPackName_zh_tw;
			}
			return group.strPackName_en_us;
		}
		private void mEmojiPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			this.EmojiSelect.SelectIndex = this.mEmojiPivot.SelectedIndex;
		}
		private void emojiPad_mItemClicked(object sender, object args)
		{
			int smiley = (int)args;
			this.EmojiClick(smiley);
		}
		private void emojiImage_Click(object sender, RoutedEventArgs e)
		{
			ImageButton imageButton = sender as ImageButton;
			if (imageButton == null)
			{
				return;
			}
			int smiley;
			if (imageButton.get_Tag() is string)
			{
				smiley = int.Parse(imageButton.get_Tag() as string);
			}
			else
			{
				smiley = (int)imageButton.get_Tag();
			}
			if (this.EmojiClick != null)
			{
				this.EmojiClick(smiley);
			}
		}
		private void initCustomSmiley()
		{
			this.allCustomSmiley = CustomSmileyManager.GetInstance().getAllCustomSmiley();
			int num = this.allCustomSmiley.get_Count() / 8;
			if (this.allCustomSmiley.get_Count() % 8 != 0)
			{
				num++;
			}
			this.AllCustomGrid = new GridPanel[num];
			this.mCustomPivot.get_Items().Clear();
			for (int i = 0; i < num; i++)
			{
				PivotItem pivotItem = new PivotItem();
				pivotItem.set_Margin(new Thickness(0.0, -10.0, 0.0, 0.0));
				GridPanel gridPanel = new GridPanel();
				gridPanel.CellCol = 4;
				gridPanel.CellRow = 2;
				gridPanel.set_Height(264.0);
				gridPanel.set_Width(460.0);
				gridPanel.set_HorizontalAlignment(0);
				gridPanel.set_VerticalAlignment(0);
				pivotItem.set_Content(gridPanel);
				this.mCustomPivot.get_Items().Add(pivotItem);
				this.AllCustomGrid[i] = gridPanel;
			}
			this.mCustomPivot.add_Tap(new EventHandler<GestureEventArgs>(this.onGridPanelClick));
			this.CustomSelect.DotNum = num;
		}
		private void onGridPanelClick(object sender, RoutedEventArgs e)
		{
			if (e.get_OriginalSource() is Grid && this.isDeleteState)
			{
				this.outDeleteMode();
			}
		}
		private void mCustomPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			this.CustomSelect.SelectIndex = this.mCustomPivot.SelectedIndex;
		}
		private void customImage_Click(object sender, RoutedEventArgs e)
		{
			if (!this.isCustomSmileyClickable)
			{
				return;
			}
			double nowMilliseconds = Util.getNowMilliseconds();
			if (nowMilliseconds - this.lastCliclTime < 300.0)
			{
				Log.smethod_5("SmileyOverlay", "customImage_Click too fast");
				return;
			}
			this.lastCliclTime = nowMilliseconds;
			Button button = sender as Button;
			if (button == null)
			{
				return;
			}
			if (button.get_Tag() == null)
			{
				return;
			}
			CustomSmiley customSmiley = button.get_Tag() as CustomSmiley;
			ChatPageCtrl cuChatPage = ChatContainerPage.getCuChatPage();
			BasePage topPage = PageManager.getInstance().GetTopPage();
			SendMessagePage sendMessagePage = null;
			if (topPage is SendMessagePage)
			{
				sendMessagePage = (topPage as SendMessagePage);
			}
			switch (customSmiley.Type)
			{
			case CustomSmileyType.Jsb:
				if (this.isDeleteState)
				{
					return;
				}
				if (sendMessagePage != null)
				{
					MMMessageBox.Show(strings.MassSend_WriteMessage_NotSupport, true, "确定");
					return;
				}
				if (cuChatPage != null)
				{
					cuChatPage.SendGame(1);
					return;
				}
				break;
			case CustomSmileyType.Dice:
				if (this.isDeleteState)
				{
					return;
				}
				if (sendMessagePage != null)
				{
					MMMessageBox.Show(strings.MassSend_WriteMessage_NotSupport, true, "确定");
					return;
				}
				if (cuChatPage != null)
				{
					cuChatPage.SendGame(2);
				}
				break;
			case CustomSmileyType.AddAction:
			{
				if (this.isDeleteState)
				{
					return;
				}
				ImageFilterConfig imageFilterConfig = new ImageFilterConfig(new ImageFilterCallBack(this.onUserSelectImage), ImageFilterGetPicMode.GetPicMode_Choose_With_Take, 0, 0, null);
				imageFilterConfig.GetPicMode = ImageFilterGetPicMode.GetPicMode_Choose_Exist;
				imageFilterConfig.isNeedFilter = false;
				this.pageIndexSelectPic = this.mCustomPivot.SelectedIndex;
				ToolFunction.GotoPageForUserControl("/Source/UI/ImageFilter/ImageFilterPage.xaml", new object[]
				{
					imageFilterConfig
				}, false);
				if (this.mmInputer != null)
				{
					base.get_Dispatcher().BeginInvoke(delegate
					{
						this.mmInputer.SwitchMode(ChatInputMode.InputDefault, false);
					});
					return;
				}
				break;
			}
			case CustomSmileyType.DeleteAction:
			{
				if (this.isDeleteState)
				{
					return;
				}
				List<CustomSmiley> customAddSmileys = CustomSmileyManager.getCustomAddSmileys();
				if (customAddSmileys != null && customAddSmileys.get_Count() != 0)
				{
					this.turnDeleteMode();
					return;
				}
				MMMessageBox.Show(strings.ChatCustom_Nothing_To_Delete, true, "确定");
				return;
			}
			case CustomSmileyType.Tuzki:
				if (this.isDeleteState)
				{
					return;
				}
				if (sendMessagePage != null)
				{
					MMMessageBox.Show(strings.MassSend_WriteMessage_NotSupport, true, "确定");
					return;
				}
				if (cuChatPage != null)
				{
					Uri uri = new Uri(customSmiley.ImageSrc, 2);
					StreamResourceInfo resourceStream = Application.GetResourceStream(uri);
					if (resourceStream != null && resourceStream.get_Stream() != null)
					{
						cuChatPage.SendGif(resourceStream.get_Stream(), customSmiley);
						return;
					}
				}
				break;
			case CustomSmileyType.CustomAdd:
				if (this.isDeleteState)
				{
					if (CustomSmileyManager.deleteCustomSmiley(customSmiley))
					{
						int num = this.mCustomPivot.SelectedIndex;
						this.initCustomSmiley();
						this.LoadSmiley(this.AllGrid.Length + this.AllEmojiGrid.Length);
						if (num > 0)
						{
							num = Math.Min(num, this.AllCustomGrid.Length - 1);
							this.CustomSelect.SelectIndex = num;
							this.mCustomPivot.SelectedIndex = num;
						}
						if (CustomSmileyManager.getCustomAddSmileys().get_Count() == 0)
						{
							this.outDeleteMode();
							return;
						}
					}
				}
				else
				{
					if (sendMessagePage != null)
					{
						MMMessageBox.Show(strings.MassSend_WriteMessage_NotSupport, true, "确定");
						return;
					}
					if (cuChatPage != null)
					{
						byte[] array = StorageIO.readFromFile(customSmiley.ImageSrc);
						if (array != null && array.Length > 0)
						{
							Stream gifStream = new MemoryStream(array);
							cuChatPage.SendGif(gifStream, customSmiley);
							return;
						}
					}
				}
				break;
			default:
				return;
			}
		}
		private void turnDeleteMode()
		{
			GridPanel[] allCustomGrid = this.AllCustomGrid;
			for (int i = 0; i < allCustomGrid.Length; i++)
			{
				GridPanel gridPanel = allCustomGrid[i];
				using (IEnumerator<UIElement> enumerator = gridPanel.get_Children().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						UIElement current = enumerator.get_Current();
						CustomSmileyButton customSmileyButton = current as CustomSmileyButton;
						if (customSmileyButton != null)
						{
							CustomSmiley customSmiley = customSmileyButton.get_Tag() as CustomSmiley;
							if (customSmiley != null)
							{
								if (customSmiley.Type == CustomSmileyType.CustomAdd)
								{
									customSmileyButton.showDeleteFlag();
								}
								else
								{
									if (customSmiley.Type == CustomSmileyType.DeleteAction || customSmiley.Type == CustomSmileyType.AddAction)
									{
										customSmileyButton.set_Visibility(1);
									}
								}
							}
						}
					}
				}
			}
			this.isDeleteState = true;
		}
		private void outDeleteMode()
		{
			GridPanel[] allCustomGrid = this.AllCustomGrid;
			for (int i = 0; i < allCustomGrid.Length; i++)
			{
				GridPanel gridPanel = allCustomGrid[i];
				using (IEnumerator<UIElement> enumerator = gridPanel.get_Children().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						UIElement current = enumerator.get_Current();
						CustomSmileyButton customSmileyButton = current as CustomSmileyButton;
						if (customSmileyButton != null)
						{
							CustomSmiley customSmiley = customSmileyButton.get_Tag() as CustomSmiley;
							if (customSmiley != null)
							{
								if (customSmiley.Type == CustomSmileyType.CustomAdd)
								{
									customSmileyButton.hideDeleteFlag();
								}
								else
								{
									if (customSmiley.Type == CustomSmileyType.DeleteAction || customSmiley.Type == CustomSmileyType.AddAction)
									{
										customSmileyButton.set_Visibility(0);
									}
								}
							}
						}
					}
				}
			}
			this.isDeleteState = false;
		}
		private void onUserSelectImage(Stream resultData)
		{
			if (this.mmInputer != null)
			{
				this.mmInputer.SwitchMode(ChatInputMode.InputSmileyMode, false);
			}
			if (resultData != null && resultData.get_Length() > 0L && CustomSmileyManager.addCustomSmiley(resultData))
			{
				this.initCustomSmiley();
				this.LoadSmiley(this.AllGrid.Length + this.AllEmojiGrid.Length);
			}
			if (this.pageIndexSelectPic > 0)
			{
				this.pageIndexSelectPic = Math.Min(this.pageIndexSelectPic, this.AllCustomGrid.Length - 1);
				this.CustomSelect.SelectIndex = this.pageIndexSelectPic;
				this.mCustomPivot.SelectedIndex = this.pageIndexSelectPic;
			}
		}
		public void RefreshCustomSmileys()
		{
			this.initCustomSmiley();
			this.LoadSmiley(this.AllGrid.Length + this.AllEmojiGrid.Length);
		}
		private void Grid_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			if (this.isDeleteState)
			{
				return;
			}
			this.isCustomSmileyClickable = true;
			Point arg_16_0 = e.get_ManipulationOrigin();
			if (this.checkSlideTimer != null)
			{
				this.checkSlideTimer.Stop();
			}
			this.lastTouchItem = this.getCurrentImage(sender, e);
			this.checkSlideTimer = new DispatcherTimer();
			this.checkSlideTimer.set_Interval(TimeSpan.FromMilliseconds(500.0));
			this.checkSlideTimer.add_Tick(new EventHandler(this.OnCheckSlide));
			this.checkSlideTimer.Start();
		}
		private void Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
		{
			if (this.isDeleteState)
			{
				return;
			}
			CustomSmiley currentImage = this.getCurrentImage(sender, e);
			if (this.isPreviewMode && currentImage == this.lastTouchItem)
			{
				e.set_Handled(true);
				return;
			}
			this.lastTouchItem = currentImage;
			Point arg_3D_0 = e.get_CumulativeManipulation().get_Translation();
			if (!this.isPreviewMode)
			{
				Point translation = e.get_DeltaManipulation().get_Translation();
				if (translation.get_X() * translation.get_X() + translation.get_Y() * translation.get_Y() > 25.0)
				{
					this.isCustomSmileyClickable = false;
					this.isUserSlide = true;
					return;
				}
			}
			else
			{
				this.showPreview(e);
				this.isCustomSmileyClickable = false;
				e.set_Handled(true);
			}
		}
		private void Grid_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			if (this.isDeleteState)
			{
				return;
			}
			this.isPreviewMode = false;
			this.isUserSlide = false;
			if (this.checkSlideTimer != null)
			{
				this.checkSlideTimer.Stop();
			}
			this.hidePreview();
		}
		private void OnCheckSlide(object sender, EventArgs e)
		{
			if (this.checkSlideTimer != null)
			{
				this.checkSlideTimer.Stop();
				this.checkSlideTimer = null;
			}
			if (!this.isUserSlide)
			{
				this.isPreviewMode = true;
				this.showPreview(null);
			}
		}
		private void showPreview(ManipulationDeltaEventArgs manipulationDeltaEventArgs_0)
		{
			if (this.lastTouchItem == null)
			{
				this.hidePreview();
				return;
			}
			if (this.lastTouchItem.Type != CustomSmileyType.CustomAdd && this.lastTouchItem.Type != CustomSmileyType.Tuzki)
			{
				this.hidePreview();
				return;
			}
			if (this.preViewLayout.get_Children().get_Count() > 0)
			{
				GifControl gifControl = this.preViewLayout.get_Children().get_Item(0) as GifControl;
				if (gifControl != null)
				{
					gifControl.Stop();
					gifControl.Release();
				}
				this.preViewLayout.get_Children().Clear();
			}
			GifControl gifControl2 = new GifControl();
			gifControl2.set_Width(150.0);
			gifControl2.set_Height(150.0);
			gifControl2.Stretch = 1;
			gifControl2.set_Margin(new Thickness(1.0, 5.0, 0.0, 0.0));
			gifControl2.set_VerticalAlignment(0);
			this.preViewLayout.get_Children().Add(gifControl2);
			gifControl2.Cover = this.lastTouchItem.ThumbSrc;
			if (this.lastTouchItem.Type == CustomSmileyType.Tuzki)
			{
				gifControl2.Source = this.lastTouchItem.ImageSrc;
			}
			this.preViewLayout.set_Visibility(0);
			double num = (double)(this.lastTouchItemIndex % 4 * 111 - 10);
			double num2 = (double)((this.lastTouchItemIndex > 3) ? -75 : -200);
			if (num < 5.0)
			{
				num = 5.0;
			}
			if (num > 310.0)
			{
				num = 310.0;
			}
			Canvas.SetLeft(this.preViewLayout, num);
			Canvas.SetTop(this.preViewLayout, num2);
		}
		private void hidePreview()
		{
			this.preViewLayout.set_Visibility(1);
			if (this.preViewLayout.get_Children().get_Count() > 0)
			{
				GifControl gifControl = this.preViewLayout.get_Children().get_Item(0) as GifControl;
				if (gifControl != null)
				{
					gifControl.Stop();
				}
				this.preViewLayout.get_Children().Clear();
			}
		}
		private void image2_LoadingFailed(object sender, UnhandledExceptionEventArgs e)
		{
			Log.smethod_5("SmileyOverlay", "Loading gif failed");
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.hidePreview();
			});
		}
		private CustomSmiley getCurrentImage(object sender, ManipulationStartedEventArgs manipulationStartedEventArgs_0)
		{
			if (sender == null || manipulationStartedEventArgs_0 == null)
			{
				return null;
			}
			Image image = manipulationStartedEventArgs_0.get_ManipulationContainer() as Image;
			if (image == null)
			{
				return null;
			}
			int num = (int)image.get_Tag();
			int num2 = num % 4 * 111;
			int num3 = (num < 4) ? 0 : 111;
			this.startX = (double)num2 + manipulationStartedEventArgs_0.get_ManipulationOrigin().get_X();
			this.startY = (double)num3 + manipulationStartedEventArgs_0.get_ManipulationOrigin().get_Y();
			this.lastTouchItemIndex = num;
			GridPanel gridPanel = sender as GridPanel;
			if (gridPanel == null)
			{
				return null;
			}
			if (gridPanel.get_Children().get_Count() > num)
			{
				return ((CustomSmileyButton)gridPanel.get_Children().get_Item(num)).get_Tag() as CustomSmiley;
			}
			return null;
		}
		private CustomSmiley getCurrentImage(object sender, ManipulationDeltaEventArgs manipulationDeltaEventArgs_0)
		{
			if (sender == null || manipulationDeltaEventArgs_0 == null)
			{
				return null;
			}
			double num = this.startX + manipulationDeltaEventArgs_0.get_CumulativeManipulation().get_Translation().get_X();
			double num2 = this.startY + manipulationDeltaEventArgs_0.get_CumulativeManipulation().get_Translation().get_Y();
			int num3 = (int)num / 111;
			if (num3 < 0)
			{
				num3 = 0;
			}
			if (num3 > 3)
			{
				num3 = 3;
			}
			if (num2 > 111.0)
			{
				num3 += 4;
			}
			this.lastTouchItemIndex = num3;
			GridPanel gridPanel = sender as GridPanel;
			if (gridPanel == null)
			{
				return null;
			}
			if (gridPanel.get_Children().get_Count() > num3)
			{
				return ((CustomSmileyButton)gridPanel.get_Children().get_Item(num3)).get_Tag() as CustomSmiley;
			}
			return null;
		}
		private void LoadSmiley(int progress)
		{
			if (progress >= 0 && progress < this.AllGrid.Length + this.AllEmojiGrid.Length + this.AllCustomGrid.Length)
			{
				if (progress < this.AllGrid.Length)
				{
					int progress2 = progress;
					this.AllGrid[progress2].mNPageIndex = progress2;
					this.AllGrid[progress2].mItemClicked += new MMStandardUIEvent(this.SmileyOverlay_mItemClicked);
					Image arg_BD_0 = this.AllGrid[progress2].imgContent;
					BitmapImage bitmapImage = new BitmapImage(new Uri(string.Format("/Resource/Img/BigSmileyBG/Smiley{0}.jpg", progress2), 2));
					bitmapImage.set_CreateOptions(2);
					arg_BD_0.set_Source(bitmapImage);
				}
				else
				{
					if (progress < this.AllGrid.Length + this.AllEmojiGrid.Length)
					{
						EmojiManager.GetInstance().GetEmojiCount();
						int num = progress - this.AllGrid.Length;
						this.AllEmojiGrid[num].mNPageIndex = num;
						this.AllEmojiGrid[num].mItemClicked += new MMStandardUIEvent(this.emojiPad_mItemClicked);
						Image arg_160_0 = this.AllEmojiGrid[num].imgContent;
						BitmapImage bitmapImage2 = new BitmapImage(new Uri(string.Format("/Resource/Img/BigSmileyBG/Emoj{0}.jpg", num), 2));
						bitmapImage2.set_CreateOptions(16);
						arg_160_0.set_Source(bitmapImage2);
					}
					else
					{
						int count = this.allCustomSmiley.get_Count();
						int num2 = progress - this.AllGrid.Length - this.AllEmojiGrid.Length;
						int num3 = 8 * num2;
						this.AllCustomGrid[num2].add_ManipulationStarted(new EventHandler<ManipulationStartedEventArgs>(this.Grid_ManipulationStarted));
						this.AllCustomGrid[num2].add_ManipulationDelta(new EventHandler<ManipulationDeltaEventArgs>(this.Grid_ManipulationDelta));
						this.AllCustomGrid[num2].add_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.Grid_ManipulationCompleted));
						int num4 = 0;
						while (num4 < 8 && num3 + num4 < count)
						{
							CustomSmiley customSmiley = this.allCustomSmiley.get_Item(num3 + num4);
							CustomSmileyButton customSmileyButton = new CustomSmileyButton(customSmiley.getThumbImage());
							customSmileyButton.set_Tag(this.allCustomSmiley.get_Item(num3 + num4));
							customSmileyButton.add_Click(new RoutedEventHandler(this.customImage_Click));
							customSmileyButton.set_Margin(new Thickness(3.0));
							customSmileyButton.ImgH = 105.0;
							customSmileyButton.ImgW = 105.0;
							customSmileyButton.SetIndex(num4);
							if (this.isDeleteState)
							{
								if (customSmiley.Type == CustomSmileyType.CustomAdd)
								{
									customSmileyButton.showDeleteFlag();
								}
								else
								{
									if (customSmiley.Type == CustomSmileyType.DeleteAction || customSmiley.Type == CustomSmileyType.AddAction)
									{
										customSmileyButton.set_Visibility(1);
									}
								}
							}
							this.AllCustomGrid[num2].get_Children().Add(customSmileyButton);
							num4++;
						}
					}
				}
				progress++;
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.LoadSmiley(progress);
				});
				return;
			}
		}
		private static void bIsWithoutArtSmileyPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == SmileyOverlay.bIsWithoutArtSmileyProperty)
			{
				SmileyOverlay smileyOverlay = dependencyObject_0 as SmileyOverlay;
				if (!smileyOverlay.bIsWithoutArtSmiley)
				{
					smileyOverlay.QQSmileyButton.set_Width(104.0);
					smileyOverlay.EmojiSmileyButton.set_Width(104.0);
					smileyOverlay.CustomSmileyButton.set_Visibility(0);
					smileyOverlay.ArtSmileyButton.set_Visibility(0);
					return;
				}
				smileyOverlay.QQSmileyButton.set_Width(158.0);
				smileyOverlay.EmojiSmileyButton.set_Width(158.0);
				smileyOverlay.ArtSmileyButton.set_Visibility(1);
				smileyOverlay.CustomSmileyButton.set_Visibility(1);
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/SmileyOverlay.xaml", 2));
			this.RootLayout = (Canvas)base.FindName("RootLayout");
			this.SmileyFliper = (ViewFlipper)base.FindName("SmileyFliper");
			this.QQSmileyView = (Grid)base.FindName("QQSmileyView");
			this.mSmileyPivot = (Pivot)base.FindName("mSmileyPivot");
			this.SmileyGrid1 = (SimileyPad)base.FindName("SmileyGrid1");
			this.SmileyGrid2 = (SimileyPad)base.FindName("SmileyGrid2");
			this.SmileyGrid3 = (SimileyPad)base.FindName("SmileyGrid3");
			this.SmileySelect = (SmileyViewDot)base.FindName("SmileySelect");
			this.EmojiSmileyView = (Grid)base.FindName("EmojiSmileyView");
			this.mEmojiPivot = (Pivot)base.FindName("mEmojiPivot");
			this.EmojiGrid1 = (SimileyPad)base.FindName("EmojiGrid1");
			this.EmojiGrid2 = (SimileyPad)base.FindName("EmojiGrid2");
			this.EmojiGrid3 = (SimileyPad)base.FindName("EmojiGrid3");
			this.EmojiGrid4 = (SimileyPad)base.FindName("EmojiGrid4");
			this.EmojiGrid5 = (SimileyPad)base.FindName("EmojiGrid5");
			this.EmojiSelect = (SmileyViewDot)base.FindName("EmojiSelect");
			this.ArtSmileyView = (Grid)base.FindName("ArtSmileyView");
			this.ArtSmileyGrid1 = (GridPanel)base.FindName("ArtSmileyGrid1");
			this.CustomSmileyView = (Grid)base.FindName("CustomSmileyView");
			this.mCustomPivot = (Pivot)base.FindName("mCustomPivot");
			this.CustomSelect = (SmileyViewDot)base.FindName("CustomSelect");
			this.QQSmileyButton = (ImageButton)base.FindName("QQSmileyButton");
			this.EmojiSmileyButton = (ImageButton)base.FindName("EmojiSmileyButton");
			this.ArtSmileyButton = (ImageButton)base.FindName("ArtSmileyButton");
			this.CustomSmileyButton = (ImageButton)base.FindName("CustomSmileyButton");
			this.preViewLayout = (Grid)base.FindName("preViewLayout");
		}
	}
}
